<?php

namespace App\Livewire;

use App\Models\SessionsModel;
use Livewire\Attributes\Computed;
use Livewire\Component;

class CommandsComponent extends Component
{
    public $ip;

    public $perPage = 1;

    public function mount($ip)
    {
        $this->ip = $ip;
    }

    public function loadMore()
    {
        $this->perPage = $this->perPage + 2;
    }

    #[Computed]
    public function commands()
    {
        return SessionsModel::query()->where([
            ['user_id', '=', auth()->user()->id],
            ['server', '=', $this->ip],
            ['active', '=', 1],
        ])->first()->commands()->orderBy('time')->take($this->perPage)->get();
    }

    public function render()
    {
        return view('livewire.server.commands');
    }
}
